<!--
 * FCKeditor - The text editor for internet
 * Copyright (C) 2003-2005 Frederico Caldeira Knabben
 * 
 * Licensed under the terms of the GNU Lesser General Public License:
 * 		http://www.opensource.org/licenses/lgpl-license.php
 * 
 * For further information visit:
 * 		http://www.fckeditor.net/
 * 
 * "Support Open Source software. What about a donation today?"
 * 
 * File Name: LFO_GetFile.html
 * 	Open file dialog window.
 * 
 * File Authors:
 * 		GreggP (greggp@pobox.com)
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<head>
		<title>Open File</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="robots" content="noindex, nofollow" />
		<script src="common.js" type="text/javascript"></script>
		<script type="text/javascript">
		
var oEditor		= window.parent.InnerDialogLoaded() ;
var FCK			= oEditor.FCK ;
var FCKLang		= oEditor.FCKLang ;
var FCKConfig	= oEditor.FCKConfig ;


window.onload = function()
{
	// Translate the dialog box texts.
	oEditor.FCKLanguageManager.TranslatePage(document) ;
	// Show the initial dialog content.
	GetE('divFileName').style.display = '' ;
	// Show/Hide the "Browse Server" button.
	GetE('divBrowseServer').style.display = FCKConfig.LinkBrowser ? '' : 'none' ;
	// Activate the "OK" button.
	window.parent.SetOkButton( true ) ;
}

function SetUrl( url )
{
	document.getElementById('txtUrl').value = url ;
}

//#### The OK button was hit.
function Ok()
{
	var sUrl ;

	sUrl = GetE('txtUrl').value ;
	if ( sUrl.length == 0 )
	{
		alert(FCKLang.LFONoFile) ;
		return false ;
	}
	//alert(document.getElementById('frmSaveFile').action);
	oConnector.CurrentFolder	= sUrl ;
	oConnector.SendCommand( 'GetFileContents', escape( sUrl) , GetFileContentsCallBack ) ;

}

var oConnector = new Object() ;
oConnector.CurrentFolder	= '/' ;
oConnector.ResourceType = 'File' ;

var sConnUrl = FCKConfig.BasePath + "filemanager/browser/LFO/connectors/php/connector.php";

// Gecko has some problems when using relative URLs (not starting with slash).
if ( sConnUrl.substr(0,1) != '/' && sConnUrl.indexOf( '://' ) < 0 )
	sConnUrl = window.location.href.replace( /browser.html.*$/, '' ) + sConnUrl ;

oConnector.ConnectorUrl = sConnUrl + ( sConnUrl.indexOf('?') != -1 ? '&' : '?' ) ;

oConnector.SendCommand = function( command, params, callBackFunction )
{
	var sUrl = this.ConnectorUrl + 'Command=GetFileContents' ;
	sUrl += '&Type=File' ;
	sUrl += '&CurrentFolder=' + escape( GetE('txtUrl').value ) ;
	
	var oXML = new FCKXml() ;
	oXML.LoadUrl( sUrl, callBackFunction ) ;

}

oConnector.CheckError = function( responseXml )
{
	var iErrorNumber = 0 ;
	var oErrorNode = responseXml.SelectSingleNode( 'Connector/Error' ) ;
	
	if ( oErrorNode )
	{
		iErrorNumber = parseInt( oErrorNode.attributes.getNamedItem('number').value ) ;
		
		switch ( iErrorNumber )
		{
			case 0 :
				break ;
			case 1 :	// Custom error. Message placed in the "text" attribute.
				alert( oErrorNode.attributes.getNamedItem('text').value ) ;
				break ;
			case 101 :
				alert( 'File not found' ) ;
				break ;
			case 102 :
				alert( 'Invalid file name' ) ;
				break ;
			case 103 :
				alert( 'Invalid file type' ) ;
				break ;
			case 105 :
				alert( 'You do not have permissions to open this file' ) ;
				break ;
			default :
				alert( 'Error on your request. Error number: ' + iErrorNumber ) ;
				break ;
		}
	}
	return iErrorNumber ;
}

function GetFileContentsCallBack( fckXml )
{
	if ( oConnector.CheckError( fckXml ) != 0 )
		return false;
		
	var oNode = fckXml.SelectSingleNode( 'Connector/File' ) ;
	var sFileContents = oNode.attributes.getNamedItem('contents').value ;
	var sFileName = oNode.attributes.getNamedItem('name').value ;

	FCK.SetHTML( sFileContents ) ;
	SetFileName( sFileName ) ;
	window.close() ;
	return true ;

}
		</script>
	</head>
	<body scroll="no" style="OVERFLOW: hidden">
		<div id="divFileName" style="DISPLAY: none">
			<div id="divLinkTypeUrl">
				<table cellspacing="0" cellpadding="0" width="100%" border="0" dir="ltr">
					<tr>
						<td nowrap="nowrap">
						</td>
						<td nowrap="nowrap">&nbsp;</td>
						<td nowrap="nowrap" width="100%">
							<span fckLang="LFOFileName">File Name</span><br />
							<input id="txtUrl" style="WIDTH: 100%" type="text" value="/files/readme.html" />
						</td>
					</tr>
				</table>
				<br />
				<div id="divBrowseServer">
				<input type="button" value="Browse Server" fckLang="DlgBtnBrowseServer" onClick="BrowseServer();" />
				</div>
			</div>
		</div>
	</body>
</html>
